﻿using FUSE.AzureConfig.Tasks;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AzureGenCLI
{
    class Program
    {
        static void Main(string[] args)
        {
            GenerateConfig();
            AlterAzureFiles();
        }

        static void GenerateConfig()
        {
            var dir = @"C:\dev\git_ws\AzureConfigGen\data\in";
            var outfile = @"C:\dev\git_ws\AzureConfigGen\data\generated_conf.js";
            var conf = new SpecExtractor().Extract(dir);
            File.WriteAllText(outfile, JsonConvert.SerializeObject(conf, Formatting.Indented));
        }

        static void AlterAzureFiles()
        {
            var defaultDir = @"C:\dev\git_ws\AzureConfigGen\data";
            var outDir = Path.Combine(defaultDir, "out");
            var genFile = Path.Combine(defaultDir, "generated_conf.js");
            try
            {
                var conf = new SpecProcessor().Process(JsonConvert.DeserializeObject<AzureConfigSpec>(File.ReadAllText(genFile)));
                var fileGen = new FileGenerator();
                fileGen.AlterCsdef(conf, defaultDir, outDir);
                fileGen.AlterCscfgs(conf, defaultDir, outDir);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadLine();
        }
    }
}
